﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace SqlParaStudy
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string connString = "server=.;database=Northwind;uid=sa;pwd=123456;";
            using (SqlConnection conn = new SqlConnection(connString))
            {
                using (SqlCommand comm = new SqlCommand())
                {
                    //comm.CommandText = "select * from employees where employeeID>@N";
                    comm.CommandText = "select top (@N) * from employees";
                    comm.Connection = conn;
                    comm.Parameters.Add(new SqlParameter("@N",3));
                    conn.Open();
                    using(SqlDataReader reader= comm.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            this.textBox1.Text+= Convert.ToString(reader["LastName"])+ "\r\n";
                        }
                    }
                }   
            }
        }
    }
}
